﻿namespace LightCAD.Core.Elements
{
    public class Text : LcElement
    {
        public Text()
        {
        }
        public Vector2d Location { get; set; }
        public string Value { get; set; }

        public override LcElement Clone()
        {
            var clone = new Text();
            clone.Copy(this);
            return clone;
        }

        public override void Copy(LcElement src)
        {
            var text = ((Text)src);
        }
        public override Box2d GetBoundingBox()
        {
            return new Box2d(this.Location, this.Location);
        }
        public override Box2d GetBoundingBox(Matrix3d matrix)
        {
            return new Box2d(matrix.MultiplyPoint(this.Location), matrix.MultiplyPoint(this.Location));
        }
        public override void Scale(Vector2d basePoint, double scaleFactor)
        {
            Matrix3d matrix3 = Matrix3d.Scale(scaleFactor, basePoint);
            this.Set(matrix3.MultiplyPoint(this.Location));
            ResetBoundingBox();
        }
        public override void Scale(Vector2d basePoint, Vector2d scaleVector)
        {

            Matrix3d matrix3 = Matrix3d.Scale(scaleVector, basePoint);
            this.Set(matrix3.MultiplyPoint(this.Location));
            ResetBoundingBox();
        }
        public void Set(Vector2d? point = null, bool fireChangedEvent = true)
        {
            //PropertySetter:Point,Radius            
            if (!fireChangedEvent)
            {
                if (point != null) this.Location = point.Value;
            }
            else
            {
                bool chg_Point = (point != null && point != this.Location);
                if (chg_Point)
                {
                    OnPropertyChangedBefore(nameof(Point), this.Location, point);
                    var oldValue = this.Location;
                    this.Location = point.Value;
                    OnPropertyChangedAfter(nameof(Point), oldValue, this.Location);
                }
            }
        }
    }
}
